<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>dom更新时机</h2>
      <p>count: {{ count }}</p>
      <button v-on:click="fn">++</button>

      <ul>
        <li v-for="item in list">{{ item }}</li>
      </ul>
      <button v-on:click="handleClick">btn</button>
    </div>

    <script src="./lib/Vue3.js"></script>
    <script>
      const { createApp, nextTick } = Vue;

      createApp({
        data() {
          return {
            count: 1,
            list: [1, 2, 3, 4, 5],
          };
        },
        methods: {
          fn() {
            this.count++;
            // setTimeout(() => {
            //   this.count++;
            // }, 0);

            // 表示的是下一次时间轮询的时候再调用
            // 等待页面渲染结束以后再调用
            nextTick(() => {
              this.count++;
            });
          },
          handleClick() {
            // 在vue改变数据的时候，数据的改变和页面的渲染不是一起发生的(异步)
            this.list.push(6);
            console.log(this.list);
            nextTick(() => {
              console.log(document.querySelector("ul").clientHeight);
            });
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
